﻿namespace Mathhammer40K.Data {
    
    
    public partial class CombatInputs {
        public partial class UnitsDataTable
        {
            public void CopyAndAdd(UnitsRow rowToAdd)
            {
                UnitsRow newRow = NewUnitsRow();
                newRow.Copy(rowToAdd);

                AddUnitsRow(newRow);
            }

            public int GetRowIndex(UnitsRow rowToFind)
            {
                int index = -1;

                for (int i = 0; i < Count; i++)
                {
                    if ((Rows[i] as UnitsRow) == rowToFind)
                    {
                        index = i; // found it
                        break;
                    }
                }


                return index;
            }
        }
           
        public partial class UnitsRow
        {
            public void Init(UnitsRow row)
            {                
                Name = row.Name;
                Side = row.Side;
                WeaponSkill = row.WeaponSkill;
                BallisticSkill = row.BallisticSkill;
                Strength = row.Strength;
                Toughness = row.Toughness;
                Wounds = row.Wounds;
                Initiative = row.Initiative;
                Attacks = row.Attacks;
                Leadership = row.Leadership;
                if(!row.IsArmorSaveNull())
                    ArmorSave = row.ArmorSave;
                if (!row.IsInvulnerableSaveNull())
                    InvulnerableSave = row.InvulnerableSave;
                SpecialRules = row.SpecialRules;
                Count = row.Count;
                ToRemove = row.ToRemove;
                if(!row.IsWeaponStrengthNull())
                    WeaponStrength = row.WeaponStrength;
                if(!row.IsWeaponAPNull())
                    WeaponAP = row.WeaponAP;
                if(!row.IsWeaponShotsNull())
                    WeaponShots = row.WeaponShots;
            }

            public object[] Clone()
            {
                return (object[])ItemArray.Clone();
            }

            public void Copy(UnitsRow row)
            {
                int id = ID;
                ItemArray = row.Clone();
                ID = id;
            }
        }       
    }
}
